home *** CD-ROM | disk | FTP | other *** search
/ Supercompiler 1997 / SUPERCOMPILER97.iso / Delphi 3.0 / DATA.Z / EMPFORM.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-01-30  |  3.5 KB  |  118 lines

  1. unit EmpForm;
  2.  
  3. {
  4.   This program demonstrates using TClientDataSet in a distributed data
  5.   application.  The data comes from a separate OLE Automation server,
  6.   so before running this project you must compile and run EmpServ.dpr.
  7. }
  8.  
  9. interface
  10.  
  11. uses
  12.   SysUtils, Forms, Dialogs, ExtCtrls, StdCtrls, Mask, Classes,
  13.     DBClient, Db, Controls, DBCtrls, ComCtrls;
  14.  
  15. type
  16.   TEmployeeForm = class(TForm)
  17.     Label2: TLabel;
  18.     UpdateButton: TButton;
  19.     UndoButton: TButton;
  20.     QueryButton: TButton;
  21.     DBText1: TDBText;
  22.     FirstName: TDBEdit;
  23.     LastName: TDBEdit;
  24.     PhoneExt: TDBEdit;
  25.     HireDate: TDBEdit;
  26.     Salary: TDBEdit;
  27.     EmpData: TDataSource;
  28.     DBNavigator1: TDBNavigator;
  29.     Employees: TClientDataSet;
  30.     RemoteServer1: TRemoteServer;
  31.     StatusBar1: TStatusBar;
  32.     procedure QueryButtonClick(Sender: TObject);
  33.     procedure UpdateButtonClick(Sender: TObject);
  34.     procedure UndoButtonClick(Sender: TObject);
  35.     procedure EmployeesReconcileError(DataSet: TClientDataSet;
  36.      E: EReconcileError; UpdateKind: TUpdateKind; var Action: TReconcileAction);
  37.     procedure EmpDataDataChange(Sender: TObject; Field: TField);
  38.   end;
  39.  
  40. var
  41.   EmployeeForm: TEmployeeForm;
  42.  
  43. implementation
  44.  
  45. {$R *.DFM}
  46.  
  47. procedure TEmployeeForm.QueryButtonClick(Sender: TObject);
  48. begin
  49.  
  50.   { Get data from the server.  The number of records retrieved is dependent on
  51.     the PacketRecords property of TClientDataSet.  As the user scrolls through
  52.     the data, additional records a retrieved in separate data packets. }
  53.  
  54.   Employees.Close;
  55.   Employees.Open;
  56.  
  57. end;
  58.  
  59. procedure TEmployeeForm.UpdateButtonClick(Sender: TObject);
  60. begin
  61.  
  62.   { Apply any edits.  The parameter indicates the number of errors which
  63.     are allowed before the updating is aborted.  A value of -1 indicates that
  64.     all successful updates be applied regardless of the number of errors. }
  65.  
  66.   Employees.ApplyUpdates(-1);
  67. end;
  68.  
  69. procedure TEmployeeForm.UndoButtonClick(Sender: TObject);
  70. begin
  71.  
  72.   { Here we demonstrate a new feature in TClientDataSet, the ability to
  73.     undo changes in reverse order.  The True parameter indicates that the
  74.     cursor should be repositioned to record association with the change.
  75.     If False is passed, the cursor postion remains unchanged. }
  76.  
  77.  
  78.   Employees.UndoLastChange(True);
  79.  
  80. end;
  81.  
  82. procedure TEmployeeForm.EmployeesReconcileError(DataSet: TClientDataSet;
  83.   E: EReconcileError; UpdateKind: TUpdateKind; var Action: TReconcileAction);
  84. var
  85.   EmpNo: Variant;
  86. begin
  87.  
  88.   { This is a very simple error handler for the reconcile process.  If there
  89.     are any errors during the updates on the server we will be notified here
  90.     to display the employee an error and choose an action to take. }
  91.  
  92.   EmpNo := VarToStr(DataSet.Fields[0].OldValue);
  93.   ShowMessage(Format('Emp#: %s, %s', [EmpNo, E.Message]));
  94.  
  95.   { The Action parameter indicates what to do following the error.  The
  96.     raSkip value means we should leave the record in the change log and keep
  97.     processing.  We could also specify raRevert to remove the change log
  98.     entry or raAbort to abort the reconcile operation. }
  99.  
  100.   Action := raSkip;
  101.  
  102. end;
  103.  
  104. procedure TEmployeeForm.EmpDataDataChange(Sender: TObject; Field: TField);
  105. begin
  106.  
  107.   { This code is used to update the status bar to show the number of
  108.     records that have been retrieved an our relative position with the dataset. }
  109.  
  110.   with Employees do
  111.     if Active then
  112.       StatusBar1.Panels[1].Text := Format(' %d of %d', [RecNo, RecordCount]);
  113.  
  114. end;
  115.  
  116.  
  117. end.
  118.